package main

import (
	"fmt"
	"time"
)

func f(form string) {
	for i := 0; i < 3; i++ {
		fmt.Println(form, ":", i)
	}
}

// func worker(done chan bool) {
// 	fmt.Print("Working....")
// 	time.Sleep(time.Second)
// 	fmt.Print("Done")
// 	done <- true
// }

/*
When using channels as function parameters, you can specify if
a channel is meant to only send or receive values.
This specificity increases the type-safety of the program.
*/
func ping(pings chan<- string, msg string) {
	pings <- msg
}

func pong(pings <-chan string, pongs chan<- string) {
	msg := <-pings
	pongs <- msg
}

func main() {
	// f("direct main")
	// go f("routine")
	// go func(msg string) {
	// 	fmt.Println(msg)
	// }("going")

	// // channel
	// message := make(chan string)
	// go func() {
	// 	message <- "ping"
	// }()

	// msg := <-message
	// fmt.Println(msg)
	// time.Sleep(time.Second)
	// fmt.Println("done")
	done := make(chan bool, 1)
	go worker(done)
	// done channel's function is to notify that we have finished the work
	<-done

	pings := make(chan string, 1)
	pongs := make(chan string, 1)

	ping(pings, "passed message")
	pong(pings, pongs)
	fmt.Println(<-pongs)
}
